import request from '@/utils/http'

export class RuleService {
	
	static getLoadAll(params:any) {
	  return request.post<any>({
	    url: '/data-rule/rule/load/all',
		params
	  })
	}
	
	static save(params:any) {
	  return request.post<any>({
	    url: '/data-rule/rule/save',
		params
	  })
	}
	
	static delete(id:string) {
	  return request.del<any>({
	    url: '/data-rule/rule/detain/'+id,
	  })
	}
	
	static saveSql(params:any) {
	  return request.post<any>({
	    url: '/data-rule/rule/sql/save',
		params
	  })
	}
	
	static getSql(id:string) {
	  return request.get<any>({
	    url: '/data-rule/rule/'+id+'/sql',
	  })
	}
	
	static executeSql(id:string) {
	  return request.post<any>({
	    url: '/data-rule/rule/'+id+'/execute/sql',
	  })
	}
	
	static generateFields(id:string) {
	  return request.post<any>({
	    url: '/data-rule/rule/'+id+'/gen/fields',
	  })
	}
	
	static getFieldByPages(params:any) {
	  return request.post<any>({
	    url: '/data-rule/rule/field/pages',
		params
	  })
	}
	
	static saveField(params:any) {
	  return request.post<any>({
	    url: '/data-rule/rule/field/save',
		params
	  })
	}
	
	static deleteFields(ids: string[] | string) {
		const idString = Array.isArray(ids) ? 
		ids.filter(id => !!id).join(',') : 
		ids.toString();
		return request.del<any>({
			url: '/data-rule/rule/field/'+encodeURIComponent(idString),
		})
	}
	
	static getColumns(rulecode: string) {
		return request.get<any>({
			url: '/data-rule/rule/'+rulecode+'/columns',
		})
	}
}

